<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2020/5/12
 * Time: 15:39
 */

namespace app\admin\controller;

use think\Db;
use think\Request;

class Report extends Base
{
    /**
     * 举报列表
     * @return mixed|\think\response\Json
     */
    public function index(){
        if(request()->isAjax()){
            $NowPage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('report')
                ->join('up_u_user uuu1', 'uuu1.user_id = report_user_id', 'left')
                ->join('up_u_user uuu2', 'uuu2.user_id = report_other_user_id', 'left')
                ->count();// 获取总条数
            $lists = Db::name('report')
                ->join('up_u_user uuu1', 'uuu1.user_id = report_user_id', 'left')
                ->join('up_u_user uuu2', 'uuu2.user_id = report_other_user_id', 'left')
                ->field('report_id, uuu1.user_username user_name, uuu1.user_phone, uuu2.user_username other_user_name, 
                uuu2.user_phone other_user_phone, report_time, report_status, report_do_time')
                ->page($NowPage,$limits)
                ->order('report_time desc')
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        return $this->fetch();
    }
    
    /**
     * 标记已处理
     * @return \think\response\Json
     */
    public function doReport(){
        $report_id = input('id');
        $data['report_do_time'] = date('Y-m-d H:i:s',time());
        $data['report_status'] = 2;
        $res = Db::table('up_report')->where('report_id', $report_id)->update($data);
        if($res){
            return json(['code' => 200, 'msg' => '处理成功']);
        }else{
            return json(['code' => 100, 'msg' => '处理失败']);
        }
    }
    
    /**
     * 删除举报
     * @return \think\response\Json
     */
    public function reportDel(){
        $report_id = input('id');
        $res = Db::table('up_report')->delete($report_id);
        if($res){
            return json(['code' => 200, 'msg' => '删除成功']);
        }else{
            return json(['code' => 100, 'msg' => '删除失败']);
        }
    }
}